package org.jmetrix.jmx;

import org.jmetrix.group.GroupAggregationTree;
import org.jmetrix.monitor.impl.ExposerMonitor;

import java.lang.management.ManagementFactory;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @author Konstantin Kuzmin
 * @version $Revision$
 * @since 07.10.11
 */
public class JmxMonitor extends ExposerMonitor {
    public JmxMonitor() {
        setMetrixAggregator(new GroupAggregationTree());
        final JmxExposer jmxExposer = new JmxExposer();
        jmxExposer.setMBeanServer(ManagementFactory.getPlatformMBeanServer());
        setExposer(jmxExposer);
        setScheduledExecutorService(new ScheduledThreadPoolExecutor(1)); //TODO make sure the created thread is daemon
    }

    @Override
    public void stop() {
        super.stop();
        ((JmxExposer) getExposer()).unregisterMBeans();
    }
}
